
<%@ page import="com.cx.dto.PageDto" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" href="../static/bootstrap/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="../static/css/base.css"/>
    <link rel="stylesheet" href="../static/css/index.css">
</head>
<body>
<%--<div class="head" style="background-image: url(../img/bg_header_index_top.png); height: 50px">--%>
<%--    <div class="container-fluid">--%>
<%--        <!-- Brand and toggle get grouped for better mobile display -->--%>
<%--        <div class="navbar-header">--%>
<%--            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse"--%>
<%--                    data-target="#bs-example-navbar-collapse-1" aria-expanded="false">--%>
<%--                <span class="sr-only">Toggle navigation</span>--%>
<%--                <span class="icon-bar"></span>--%>
<%--                <span class="icon-bar"></span>--%>
<%--                <span class="icon-bar"></span>--%>
<%--            </button>--%>
<%--            <a class="navbar-brand" href="#">此处是logo</a>--%>
<%--        </div>--%>

<%--        <!-- Collect the nav links, forms, and other content for toggling -->--%>
<%--        <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">--%>
<%--            <ul class="nav navbar-nav" style="margin-right: 2px">--%>
<%--                <li><a href="#">首页</a></li>--%>
<%--                <li><a href="http://localhost:8888/html/allhotel.html">国内酒店</a></li>--%>
<%--                <li><a href="#">国外酒店</a></li>--%>
<%--                <li><a href="#">特卖专区</a></li>--%>
<%--                <li class="active"><a href="http://localhost:8888/html/index.html">旗下品牌</a></li>--%>
<%--                <li><a href="#">华住会</a></li>--%>
<%--                <li><a href="#">华住商旅</a></li>--%>
<%--            </ul>--%>

<%--            <ul class="nav navbar-nav navbar-right">--%>
<%--                <li style="margin-right: 30px;margin-top: 10px">--%>
<%--                    <button type="button" class="btn btn-primary small " style=";height: 30px;width:70px">登录</button>--%>
<%--                </li>--%>
<%--                <li style="margin-right: 30px;margin-top: 10px">--%>
<%--                    <button type="button" class="btn btn-default small active" style=";height: 30px;width:70px">注册--%>
<%--                    </button>--%>
<%--                </li>--%>
<%--            </ul>--%>
<%--        </div>--%>
<%--    </div>--%>
<%--</div>--%>
<script src="../static/bootstrap/js/jquery-3.3.1.js"></script>
<script src="../static/bootstrap/js/bootstrap.min.js"></script>
<div class="container-fluid">
    <div class="row" style="margin-top: 50px;">
        <p class="col-md-offset-1 title1" style="color: mediumpurple">日  志  消  息</p>
        <hr>
        <div class="col-md-offset-1 col-md-10" style="font-size: 18px">
            <table class="table table-striped" style="text-align: center">
                <tr>
                    <th style="display: none">编号</th>
                    <th style="text-align: center">类型</th>
                    <th style="text-align: center">内容</th>
                    <th style="text-align: center">日期</th>
                    <th style="text-align: center">操作</th>
                </tr>
                <c:forEach items="${logs}" var="log">

                    <tr>
                        <td style="display:none;">${log.id}</td>
                        <c:choose>
                            <c:when test="${log.status == 1}">
                                <td style="font-weight: 600">${log.type}</td>
                                <c:choose>
                                    <c:when test="${fn:length(log.context) > 20}">
                                        <td style="width: 400px;font-weight: 600">${fn:substring(log.context,0,18)}...</td>
                                    </c:when>
                                    <c:otherwise>
                                        <td style="width: 400px;font-weight: 600">${log.context}</td>
                                    </c:otherwise>
                                </c:choose>
                                <td style="font-weight: 600">${log.date}</td>
                            </c:when>
                            <c:otherwise>
                                <td>${log.type}</td>
                                <c:choose>
                                    <c:when test="${fn:length(log.context) > 20}">
                                        <td style="width: 400px">${fn:substring(log.context,0,18)}...</td>
                                    </c:when>
                                    <c:otherwise>
                                        <td style="width: 400px">${log.context}</td>
                                    </c:otherwise>
                                </c:choose>
                                <td>${log.date}</td>
                            </c:otherwise>
                        </c:choose>

                        <td style="width:100px" id="${log.id}"><button onclick="info(this)" data-toggle="modal" data-target="#myModal" style="font-size:7px;width: 30px">查看</button>&nbsp;<button style="font-size:7px;width: 30px" onclick="dellog(this)">删除</button></td>
                    </tr>

                </c:forEach>
            </table>
            <div style="width: 300px;height: 34px;margin: 0 auto">
                <button class="btn" id="prebt" onclick="pre()" style="line-height: 34px">上一页</button>
<%--                <%--%>

<%--                    List<String> pages = new ArrayList<>();--%>
<%--                    PageDto pageDto = (PageDto) request.getAttribute("page");--%>
<%--                    System.out.println(pageDto);--%>
<%--                    for (int i=1;i<=pageDto.getMaxPage();i++){--%>
<%--                        pages.add(String.valueOf(i));--%>
<%--                    }--%>
<%--                    request.setAttribute("pageNum", pages);--%>
<%--                %>--%>
                <select name="jumpPage" id="jumpPage" style="height: 34px" onchange="jump()">
<%--                    <c:forEach items="pageNum" var="p">--%>
<%--                        <c:choose>--%>
<%--                            <c:when test="${p==page.nowPage}">--%>
<%--                                <option value="${p}" selected="selected" onblur="jump()">第${p}页</option>--%>
<%--                            </c:when>--%>
<%--                            <c:otherwise>--%>
<%--                                <option value="${p}" onblur="jump()">第${p}页</option>--%>
<%--                            </c:otherwise>--%>

<%--                        </c:choose>--%>

<%--                    </c:forEach>--%>
                    <%

                        PageDto pageDto = (PageDto) request.getAttribute("page");
                        for (int i = 1;i<=pageDto.getMaxPage();i++){
                            String p = String.valueOf(i);
                            request.setAttribute("p",p);

                    %>
                        <c:choose>
                            <c:when test="${p==page.nowPage}">
                                <option value="${p}" selected="selected">第${p}页</option>
                            </c:when>
                            <c:otherwise>
                                <option value="${p}">第${p}页</option>
                            </c:otherwise>

                        </c:choose>
                    <% } %>


                </select>
                <button class="btn" id="nxtbt" onclick="next()" style="line-height: 34px">下一页</button>

            </div>
        </div>
    </div>
</div>

<div style="display: none">
    <p id="maxCount">${page.maxCount}</p>
    <p id="maxPage">${page.maxPage}</p>
    <p id="nowPage">${page.nowPage}</p>
</div>

<!-- Modal -->
<div class="modal" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">详细日志</h4>
                </div>
                <div class="modal-body">
                    <form>
                        <div class="form-group">
                            <label for="type">信息类型</label>
                            <input type="text" class="form-control" id="type" readonly>
                        </div>
                        <div class="form-group">
                            <label for="datetime">接收日期</label>
                            <input type="text" class="form-control" id="datetime" readonly>
                        </div>
                        <div class="form-group">
                            <label for="context">信息内容</label>
                            <textarea id="context" class="form-control" rows="3" readonly></textarea>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal" onclick="fresh()">Close</button>
                </div>
            </div>
        </div>
    </div>
</div>


<script>
    var maxCount = parseInt($('#maxCount').text())
    var maxPage = parseInt($('#maxPage').text())
    var nowPage = parseInt($('#nowPage').text())
    console.log(maxCount)
    console.log(maxPage)
    console.log(nowPage)

    function next(){

        if (nowPage <maxPage){
            nowPage +=1
            location.href="/user/getlogmessage?maxCount="+maxCount+"&maxPage="+maxPage+"&nowPage="+nowPage

        }else{
            alert("已经到底了")
        }
    }

    function pre(){

        if (nowPage > 1){
            nowPage -=1
            location.href="/user/getlogmessage?maxCount="+maxCount+"&maxPage="+maxPage+"&nowPage="+nowPage

        }else{
            alert("已经到底了")
        }
    }

    function jump() {

        console.log("jump!")
        var selectPage = $("#jumpPage option:selected").val();
        if (selectPage!=nowPage){
            nowPage=selectPage
            location.href="/user/getlogmessage?maxCount="+maxCount+"&maxPage="+maxPage+"&nowPage="+nowPage
        }



    }
    function fresh() {

        location.href="/user/getlogmessage?maxCount="+maxCount+"&maxPage="+maxPage+"&nowPage="+nowPage

    }


    function info(obj){
        var id = $(obj).parent().attr('id')
        console.log(id)

        $.ajax({
            url:"/user/afterread?id="+id,
            type:"get",
            dataType:"json",
            success:function (data) {
                console.log(data)

                $('#type').val(data.type)
                $('#datetime').val(data.date)
                $('#context').val(data.context)

            }
        })



    }

    function dellog(obj){
        var id = $(obj).parent().attr('id')
        console.log(id)

        $.ajax({
            url:"/user/deletelog?id="+id,
            type:"get",
            dataType:"json",
            success:function (data) {
                console.log(data)
                fresh()

            }
        })



    }






</script>
</body>
</html>